package com.bsoft.gol.hbs.healthinfo;

import com.bsoft.gol.hbs.bean.exception.ServiceException;

import java.util.Objects;

/**
 * 持有状态信息
 */
public class StateContext {

    /**
     * 文章主键
     */
    private String articleId;

    /**
     * 文章状态对象
     */
    private State state;

    public StateContext() {
    }

    public State getState() {
        return state;
    }

    public void setState(State state) {
        this.state = state;
    }

    public String getArticleId() {
        return articleId;
    }

    public void setArticleId(String articleId) {
        this.articleId = articleId;
    }

    public StateContext next() {
        State next;
        if (Objects.nonNull((next = state.getNext())) && state.forwardNext()) {
            this.state = next;
        } else {
            throw new ServiceException(this.state.getErrorMessage());
        }
        return this;
    }

    public StateContext prev() {
        State prev;
        if (Objects.nonNull((prev = state.getPrev())) && state.forwardPrev()) {
            this.state = prev;
        } else {
            throw new ServiceException(this.state.getErrorMessage());
        }
        return this;
    }


}
